package cn.zzuisa.controller;


import cn.zzuisa.service.DissService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.zzuisa.base.PageRequest;
import cn.zzuisa.base.R;
import cn.zzuisa.entity.Diss;

import java.util.Arrays;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author frank
 * @since 2019-05-12
 */
@Api(tags = "举办管理")
@RestController
@RequestMapping("/diss")
public class DissController {

    @Autowired
    DissService dissMapper;

    @PostMapping("/add")
    public R<Diss> add(@RequestBody Diss diss) {
        dissMapper.save(diss);
        return R.ok(diss);
    }

    @GetMapping("list")
    public R<IPage<Map<String,Object>>> list(PageRequest pageRequest) {
        IPage<Map<String,Object>> page = new Page<>(pageRequest.getCurrent(),pageRequest.getSize());
        IPage<Map<String,Object>> result = dissMapper.pageDiss(page);
        return R.ok(result);
    }

    @DeleteMapping("rm")
    public R<String> rm(Long[] ids) {
        dissMapper.removeByIds(Arrays.asList(ids));
        return R.ok("删除成功");
    }

}
